﻿using System.Web.Mvc;
using DemoMVC.Models;
using Highcharts.Core;
using Highcharts.Core.Data.Chart;
using Highcharts.Core.Options;
using Highcharts.Core.PlotOptions;

namespace DemoMVC.Controllers
{
    public class LineChartController : Controller
    {
        //
        // GET: /LineChart/

        public ActionResult Index()
        {
            return View(GetViewData());
        }

        private static ChartViewData GetViewData()
        {

            var chartOptions = new ChartOptions
            {
                Title = new Title("Estimativa da população mundial por região"),
                SubTitle = new SubTitle("fonte: wikipedia.org"),
                PlotOptions = new PlotOptionsArea
                {
                    stacking = Stacking.percent,
                    lineColor = "#ffffff",
                    lineWidth = 1,
                    fillOpacity = 0.45
                },
                Tooltip = new ToolTip(@"Highcharts.numberFormat(this.percentage, 1) + '% ('+ Highcharts.numberFormat(this.y, 0, ',') +' milhões)'")
            };

            //Chart Axis
            chartOptions.YAxis.Add(new YAxisItem { title = new Title("Porcentagem") });
            chartOptions.XAxis.Add(new XAxisItem { categories = new object[] { "1750", "1800", "1850", "1900", "1950", "1999", "2050" } });

            //Chart Data (series)
            chartOptions.Series.Add(new Serie { name = "Ásia", data = new object[] { 502, 635, 809, 947, 1402, 3634, 5268 } });
            chartOptions.Series.Add(new Serie { name = "África", data = new object[] { 106, 107, 111, 133, 221, 767, 1766 } });
            chartOptions.Series.Add(new Serie { name = "Europa", data = new object[] { 163, 203, 276, 408, 547, 729, 628 } });
            chartOptions.Series.Add(new Serie { name = "América", data = new object[] { 18, 31, 54, 156, 339, 818, 1201 } });
            chartOptions.Series.Add(new Serie { name = "Oceânia", data = new object[] { 2, 2, 2, 6, 13, 30, 46 } });

            return new ChartViewData
            {
                ChartAreaData = chartOptions
            };
        }

    }
}
